package cn.wolfcode.p2p.bussness.service.impl;

import cn.wolfcode.p2p.base.query.QueryObject;
import cn.wolfcode.p2p.bussness.domain.PlatformBankInfo;
import cn.wolfcode.p2p.bussness.mapper.PlatformBankInfoMapper;
import cn.wolfcode.p2p.bussness.query.PlatformBankinfoQueryObject;
import cn.wolfcode.p2p.bussness.service.IPlatformBankInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class PlatformBankInfoServiceImpl implements IPlatformBankInfoService {

    @Autowired
    private PlatformBankInfoMapper PlatformBankInfoMapper;

    @Override
    public int save(PlatformBankInfo platformBankInfo) {
        return PlatformBankInfoMapper.insert(platformBankInfo);
    }

    @Override
    public int update(PlatformBankInfo platformBankInfo) {
        return PlatformBankInfoMapper.updateByPrimaryKey(platformBankInfo);
    }

    @Override
    public PlatformBankInfo get(Long id) {
        return PlatformBankInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<PlatformBankInfo> queryPage(QueryObject qo) {
        PageHelper.startPage(qo.getPageNum(), qo.getPageSize());
        List<PlatformBankInfo> list = PlatformBankInfoMapper.selectList(qo);
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(PlatformBankInfo platformBankInfo) {
        if (platformBankInfo.getId() == null) {
            this.save(platformBankInfo);
        } else {
            this.update(platformBankInfo);
        }
    }

    @Override
    public List<PlatformBankInfo> selectAll() {
        PlatformBankinfoQueryObject qo = new PlatformBankinfoQueryObject();
        return PlatformBankInfoMapper.selectList(qo);
    }
}
